home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / UUCP / UUXQT.C < prev   
C/C++ Source or Header  |  1993-10-03  |  51KB  |  1,482 lines

  1. /*
  2.       Program:    uuxqt.c              23 September 1991
  3.       Author:     Mitch Mitchell
  4.       Email:      mitch@harlie.lonestar.org
  5.  
  6.       This is a re-write of the (much cleaner) UUXQT.C originally
  7.       distributed with UUPC/Extended.  The modifications are
  8.       intended primarily to lay a foundation for support for the
  9.       more advanced features of UUX.
  10.  
  11.       Usage:      uuxqt -xDEBUG -sSYSTEM
  12. */
  13.  
  14. /*--------------------------------------------------------------------*/
  15. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  16. /*       Wonderworks.                                                 */
  17. /*                                                                    */
  18. /*       All rights reserved except those explicitly granted by       */
  19. /*       the UUPC/extended license agreement.                         */
  20. /*--------------------------------------------------------------------*/
  21.  
  22. /*--------------------------------------------------------------------*/
  23. /*                          RCS Information                           */
  24. /*--------------------------------------------------------------------*/
  25.  
  26. /*
  27.  *    $Id: uuxqt.c 1.18 1993/10/03 22:10:24 ahd Exp $
  28.  *
  29.  *    Revision history:
  30.  *    $Log: uuxqt.c $
  31.  * Revision 1.18  1993/10/03  22:10:24  ahd
  32.  * Use signed for length of parameters
  33.  *
  34.  * Revision 1.17  1993/10/03  20:43:08  ahd
  35.  * Normalize comments to C++ double slash
  36.  *
  37.  * Revision 1.16  1993/09/29  23:29:56  ahd
  38.  * Add xqtrootdir for UUXQT
  39.  *
  40.  * Revision 1.15  1993/09/20  04:48:25  ahd
  41.  * TCP/IP support from Dave Watt
  42.  * 't' protocol support
  43.  * OS/2 2.x support (BC++ 1.0 for OS/2)
  44.  *
  45.  * Revision 1.14  1993/08/03  03:35:58  ahd
  46.  * Correct path pointer to initialized variable
  47.  *
  48.  * Revision 1.13  1993/08/03  03:11:49  ahd
  49.  * Initialize buffer for shell() in non-Windows environment
  50.  *
  51.  * Revision 1.12  1993/07/31  16:27:49  ahd
  52.  * Changes in support of Robert Denny's Windows support
  53.  *
  54.  * Revision 1.11  1993/07/24  03:40:55  ahd
  55.  * Agressively trap carriage returns at ends of lines (from X.* files
  56.  * being edited by elves with DOS editors!)
  57.  *
  58.  * Revision 1.10  1993/07/20  21:45:37  ahd
  59.  * Don't delete file after -2 abort from UUXQT
  60.  *
  61.  * Revision 1.9  1993/06/26  16:01:48  ahd
  62.  * Normalize white space used to parse strings
  63.  *
  64.  * Revision 1.8  1993/06/13  14:06:00  ahd
  65.  * Correct off-by-one error in RMAIL arg parse loop which crashed UUXQT
  66.  * on long system names
  67.  *
  68.  * Revision 1.7  1993/04/11  00:35:46  ahd
  69.  * Global edits for year, TEXT, etc.
  70.  *
  71.  * Revision 1.6  1993/04/05  04:35:40  ahd
  72.  * Use timestamp/file size information returned by directory search
  73.  *
  74.  * Revision 1.5  1992/11/25  12:59:17  ahd
  75.  * Change NUL to /dev/nul to prevent ImportPath() mangling.
  76.  *
  77.  * Revision 1.4  1992/11/23  03:56:06  ahd
  78.  * Selected fixes for use of generlized uux commands
  79.  *
  80.  * Revision 1.3  1992/11/19  03:03:33  ahd
  81.  * drop rcsid
  82.  */
  83.  
  84. /*--------------------------------------------------------------------*/
  85. /*                        System include files                        */
  86. /*--------------------------------------------------------------------*/
  87.  
  88. #include <stdio.h>
  89. #include <stdlib.h>
  90. #include <string.h>
  91. #include <ctype.h>
  92. #include <errno.h>
  93. #include <time.h>
  94. #include <fcntl.h>
  95. #include <process.h>
  96. #include <sys/types.h>
  97. #include <sys/stat.h>
  98. #include <io.h>
  99.  
  100. #ifdef _Windows
  101. #include <windows.h>
  102. #endif
  103.  
  104. /*--------------------------------------------------------------------*/
  105. /*                    UUPC/extended include files                     */
  106. /*--------------------------------------------------------------------*/
  107.  
  108. #include "lib.h"
  109. #include "arpadate.h"
  110. #include "dater.h"
  111. #include "expath.h"
  112. #include "getopt.h"
  113. #include "getseq.h"
  114. #include "hlib.h"
  115. #include "hostable.h"
  116. #include "import.h"
  117. #include "lock.h"
  118. #include "logger.h"
  119. #include "pushpop.h"
  120. #include "readnext.h"
  121. #include "security.h"
  122. #include "timestmp.h"
  123. #include "usertabl.h"
  124. #include "execute.h"
  125.  
  126. #ifdef _Windows
  127. #include "winutil.h"
  128. #endif
  129.  
  130. currentfile();
  131.  
  132. /*--------------------------------------------------------------------*/
  133. /*                      Execution flag defines                        */
  134. /*--------------------------------------------------------------------*/
  135.  
  136. typedef enum {
  137.         X_OUTPUT,     /* 'O' return output to "outnode"       */
  138.         X_FAILED,     /* 'Z' send status if command failed    */
  139.         X_SUCCESS,    /* 'n' send status if command succeeded */
  140.         X_INPUT,      /* 'B' return command input on error    */
  141.         X_USEEXEC,    /* 'E' process command using exec(2)    */
  142.         X_STATFIL,    /* 'M' return status to file on remote  */
  143.  
  144.         S_CORRUPT,
  145.         S_EMPTY,
  146.         S_NOREAD,
  147.         S_NOWRITE,
  148.         S_STDIN,
  149.  
  150.         E_NORMAL,
  151.         E_NOACC,
  152.         E_SIGNAL,
  153.         E_STATUS,
  154.         E_NOEXE,
  155.         E_FAILED,
  156.  
  157.         UU_LAST
  158.  
  159.         } UU_FLAGS;
  160.  
  161. /*--------------------------------------------------------------------*/
  162. /*                          Global Variables                          */
  163. /*--------------------------------------------------------------------*/
  164.  
  165. static char *spool_fmt = SPOOLFMT;
  166. static char *dataf_fmt = DATAFFMT;
  167. static char *send_cmd  = "S %s %s %s -%s %s 0666 %s\n";
  168.  
  169. /*--------------------------------------------------------------------*/
  170. /*                        Internal prototypes                         */
  171. /*--------------------------------------------------------------------*/
  172.  
  173. static void usage( void );
  174.  
  175. static boolean copylocal(const char *from, const char *to);
  176.  
  177. static boolean do_uuxqt( const char *sysname );
  178.  
  179. static void process( const char *fname,
  180.                      const char *remote,
  181.                      const char *executeDirectory);
  182.  
  183. char **create_environment(const char *logname,
  184.                           const char *requestor);
  185.  
  186. static void delete_environment( char **envp);
  187.  
  188. static boolean AppendData( const char *input, FILE* dataout);
  189.  
  190. static boolean do_copy( char *localfile,
  191.                        const char *rmtsystem,
  192.                        const char *remotefile,
  193.                        const char *requestor,
  194.                        const boolean success );
  195.  
  196. static void ReportResults(const int   status,
  197.                           const char *input,
  198.                                 char *output,
  199.                           const char *command,
  200.                           const char *job_id,
  201.                           const time_t jtime,
  202.                           const char *requestor,
  203.                           const char *outnode,
  204.                           const char *outname,
  205.                           const boolean xflag[],
  206.                           const char *statfil,
  207.                           const char *machine,
  208.                           const char *user);
  209.  
  210. static int shell(char *command,
  211.                  const char *inname,
  212.                  const char *outname,
  213.                  const char *remotename,
  214.                  boolean xflag[]);
  215.  
  216. static boolean MailStatus(char *tempfile,
  217.                           char *address,
  218.                           char *subject);
  219.  
  220. /*--------------------------------------------------------------------*/
  221. /*    m a i n                                                         */
  222. /*                                                                    */
  223. /*    Main program                                                    */
  224. /*--------------------------------------------------------------------*/
  225.  
  226. void main( int argc, char **argv)
  227. {
  228.    int c;
  229.    extern char *optarg;
  230.    extern int   optind;
  231.    char *sysname = "all";
  232.  
  233. /*--------------------------------------------------------------------*/
  234. /*     Report our version number and date/time compiled               */
  235. /*--------------------------------------------------------------------*/
  236.  
  237.    debuglevel = 1;
  238.    banner( argv );
  239.  
  240. #if defined(__CORE__)
  241.    copywrong = strdup(copyright);
  242.    checkref(copywrong);
  243. #endif
  244.  
  245. /*------------------------------------------